package com.cttic.kafka2kafka.server;

import com.cttic.kafka2kafka.config.KafkaConfiguration;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaHandler;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Slf4j
public class KafKaPipelineServer {



    @Autowired
    private KafkaTemplate<String, String> kafkaTemplate;

    @KafkaListener(topics = "bd_upper_position",concurrency = "10")
    @KafkaHandler
    public void pipeline(List<ConsumerRecord<Integer,String>> records){

        log.info("拉取的记录数{}",records.size());

        records.forEach(
            record ->{
                kafkaTemplate.send(KafkaConfiguration.HADOOP_KAFKA, record.value());
            }
        );



    }
}
